package com.resolution.dietaryassessment.view.chronic.model;

import android.util.SparseArray;
import android.view.View;

import androidx.recyclerview.widget.RecyclerView;


public class CommonViewHolder extends RecyclerView.ViewHolder{

    private View mContentView;

    private SparseArray<View> mSparseArray = new SparseArray<>();

    CommonViewHolder(View itemView) {
        super(itemView);
        this.mContentView = itemView;
    }

    /**
     * 通过控件的Id获取对于的控件，如果没有则加入mSparseArray
     */
    public <T extends View> T getView(int id) {
        View view = mSparseArray.get(id);
        if (view == null) {
            view = mContentView.findViewById(id);
            mSparseArray.append(id, view);
        }
        return (T) view;
    }
}